package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SaleServerCostRecordAddDTO;
import org.jsola.hr.dto.SaleServerCostRecordUpdateDTO;
import org.jsola.hr.entity.SaleServerCostRecordDO;
import org.jsola.hr.query.SaleServerCostRecordQuery;
import org.jsola.hr.service.ISaleServerCostRecordService;
import org.jsola.hr.vo.SaleServerCostRecordVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 客户服务费记录
 *
 * @author zhr
 */
@Component
public class SaleServerCostRecordTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISaleServerCostRecordService saleServerCostRecordService;

    /**
     * 生成add测试数据
     * @return SaleServerCostRecordAddDTO
     */
    public SaleServerCostRecordAddDTO getSaleServerCostRecordAddDTO(){
        SaleServerCostRecordAddDTO saleServerCostRecordAddDTO = new SaleServerCostRecordAddDTO();
        saleServerCostRecordAddDTO.setCompanyId(getRandomValue("varchar",32));
        saleServerCostRecordAddDTO.setCompanyName(getRandomValue("varchar",50));
        saleServerCostRecordAddDTO.setCostMonth(getRandomValue("varchar",5));
        saleServerCostRecordAddDTO.setServerCost(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        saleServerCostRecordAddDTO.setRemark(getRandomValue("varchar",255));
        saleServerCostRecordAddDTO.setServerType(getRandomValue("varchar",50));
        return saleServerCostRecordAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SaleServerCostRecordUpdateDTO
     */
    public SaleServerCostRecordUpdateDTO getSaleServerCostRecordUpdateDTO(SaleServerCostRecordVO saleServerCostRecordVO){
        return saleServerCostRecordService.selectDOById(saleServerCostRecordVO.getId(), SITE_ID).to(SaleServerCostRecordUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SaleServerCostRecordQuery
     */
    public SaleServerCostRecordQuery getSaleServerCostRecordQuery() {
        SaleServerCostRecordQuery saleServerCostRecordQuery = new SaleServerCostRecordQuery();
        List<SaleServerCostRecordDO> saleServerCostRecordDOList = saleServerCostRecordService.list(new SaleServerCostRecordDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(saleServerCostRecordDOList)) {
            SaleServerCostRecordDO saleServerCostRecordDO = saleServerCostRecordDOList.get(0);
            saleServerCostRecordQuery = saleServerCostRecordDO.to(SaleServerCostRecordQuery.class);
        }
        return saleServerCostRecordQuery;
    }

    /**
     * 保存示例
     * @return SaleServerCostRecordVO
     */
    public SaleServerCostRecordVO saveSaleServerCostRecordExample(){
        SaleServerCostRecordAddDTO addDTO = this.getSaleServerCostRecordAddDTO();
        SaleServerCostRecordVO saleServerCostRecordVO = saleServerCostRecordService.save(addDTO,buildTokenUser());
        return saleServerCostRecordVO;
    }


}

